package com.imarkket.Dialogs;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;

import com.imarkket.Library.c_logging;
import com.imarkket.R;

/**
 * http://amatellanes.wordpress.com/2013/10/05/android-notificaciones-en-android-parte-2-dialogs-i/
 * Created by Sistemas on 17/06/2014.
 */

public class c_dialog_Alert extends DialogFragment {

    public interface ListenerInterface {
        public void onSubmitListenerInterface_OK(DialogFragment dialog);
    }

    private ListenerInterface listener;

    // Override the Fragment.onAttach() method to instantiate the
    // NoticeDialogListener
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        // Verify that the host activity implements the callback interface
        try {
            // Instantiate the NoticeDialogListener so we can send events to the
            // host
            listener = (ListenerInterface) activity;
        } catch (ClassCastException e) {
            // The activity doesn't implement the interface, throw exception
            throw new ClassCastException(activity.toString()
                    + " must implement DialogListener");
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(inflater.inflate(R.layout.l_df_alert, null))
                // Add action buttons
                .setNeutralButton(android.R.string.yes,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                listener.onSubmitListenerInterface_OK(c_dialog_Alert.this);
                            }
                        });

        // Create the AlertDialog object and return it
        return builder.create();
    }
}